
using System.Collections.Generic;
using System.Linq;
using InfoTech.Utilities.Generic;

namespace InfoTech.LanTranh.MucVu.Bussiness
{
    public partial class GIAODAN
    {

        public override bool Equals(object obj)
        {
            GIAODAN giaodan = obj as GIAODAN;
            if (giaodan == null) return false;
            return MAGIAODAN.Equals(giaodan.MAGIAODAN);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public string GetMaGiaoDan()
        {
            if (LUUSO.HasValue)
                if (LUUSO.Value)
                    return "";
            string result = GIAODANID.HasValue ? GIAODANID.Value.ToString("00000") : "";
            if (REF_HOGIADINH_GIAODAN.Count() > 0)
                if (REF_HOGIADINH_GIAODAN.First().PRT_HOGIADINH.IsPersistence)
                    return string.Format("{0}.{1}", REF_HOGIADINH_GIAODAN.First().PRT_HOGIADINH.GetMaHoGiaDinh(), result);
            return result;
        }

        private GIAODAN _prt_giaodan_cha;
        private GIAODAN _prt_giaodan_me;

        public GIAODAN PRT_GIAODAN_CHA
        {
            get
            {
                if (RefreshType == InfoTech.Core.Data.RefreshType.Allway || (RefreshType == InfoTech.Core.Data.RefreshType.OnlyonNull && _prt_giaodan_cha == default(GIAODAN)))
                    InfoTech.Core.Data.Receiver.TypeObject<GIAODAN>.Select(this, "PRT_GIAODAN_CHA", new[] { new Vector<string, string>("PARENTID", "MAGIAODAN"), }, InfoTech.Core.Data.RelationType.OnetoOne);
                return _prt_giaodan_cha;
            }
            set
            {
                _prt_giaodan_cha = value;
            }
        }

        public GIAODAN PRT_GIAODAN_ME
        {
            get
            {
                if (RefreshType == InfoTech.Core.Data.RefreshType.Allway || (RefreshType == InfoTech.Core.Data.RefreshType.OnlyonNull && _prt_giaodan_me == default(GIAODAN)))
                    InfoTech.Core.Data.Receiver.TypeObject<GIAODAN>.Select(this, "PRT_GIAODAN_ME", new[] { new Vector<string, string>("MOTHERID", "MAGIAODAN"), }, InfoTech.Core.Data.RelationType.OnetoOne);
                return _prt_giaodan_me;
            }
            set
            {
                _prt_giaodan_me = value;
            }
        }

        public string GetFullName()
        {
            return string.Format("{0} {1} {2}", TENTHANH, HOVATENDEM, TEN);
        }

        public string GetBirthDay()
        {
            string day = "", month = "", year = "";
            if (NGAYSINH.HasValue)
                day = NGAYSINH.Value.ToString("00") + "/";
            if (THANGSINH.HasValue)
                month = THANGSINH.Value.ToString("00") + "/";
            if (NAMSINH.HasValue)
                year = NAMSINH.Value.ToString("0000");
            return string.Format("{0}{1}{2}", day, month, year);
        }

        private IEnumerable<SOHONNHAN> _ref_sohonnhan_nguoilamchung1;

        private IEnumerable<SOHONNHAN> _ref_sohonnhan_nguoilamchung2;

        public IEnumerable<SOHONNHAN> REF_SOHONNHAN_NGUOILAMCHUNG1
        {
            get
            {
                if (RefreshType == InfoTech.Core.Data.RefreshType.Allway || (RefreshType == InfoTech.Core.Data.RefreshType.OnlyonNull && _ref_sohonnhan_nguoilamchung1 == null))
                    InfoTech.Core.Data.Receiver.TypeObject<SOHONNHAN>.Select(this, "REF_SOHONNHAN", new[] { new Vector<string, string>("MAGIAODAN", "MANHANCHUNG1") }, InfoTech.Core.Data.RelationType.OnetoMany);
                return _ref_sohonnhan_nguoilamchung1;
            }
            set
            {
                _ref_sohonnhan_nguoilamchung1 = value;
            }
        }

        public IEnumerable<SOHONNHAN> REF_SOHONNHAN_NGUOILAMCHUNG2
        {
            get
            {
                if (RefreshType == InfoTech.Core.Data.RefreshType.Allway || (RefreshType == InfoTech.Core.Data.RefreshType.OnlyonNull && _ref_sohonnhan_nguoilamchung2 == null))
                    InfoTech.Core.Data.Receiver.TypeObject<SOHONNHAN>.Select(this, "REF_SOHONNHAN", new[] { new Vector<string, string>("MAGIAODAN", "MANHANCHUNG2") }, InfoTech.Core.Data.RelationType.OnetoMany);
                return _ref_sohonnhan_nguoilamchung2;
            }
            set
            {
                _ref_sohonnhan_nguoilamchung2 = value;
            }
        }

        private IEnumerable<SOHONNHAN> _ref_sohonnhan_vo;

        private IEnumerable<SOHONNHAN> _ref_sohonnhan_chong;

        public IEnumerable<SOHONNHAN> REF_SOHONNHAN_VO
        {
            get
            {
                if (RefreshType == InfoTech.Core.Data.RefreshType.Allway || (RefreshType == InfoTech.Core.Data.RefreshType.OnlyonNull && _ref_sohonnhan_vo == null))
                    InfoTech.Core.Data.Receiver.TypeObject<SOHONNHAN>.Select(this, "REF_SOHONNHAN_VO", new[] { new Vector<string, string>("MAGIAODAN", "MAGIAODAN_VO") }, InfoTech.Core.Data.RelationType.OnetoMany);
                return _ref_sohonnhan_vo;
            }
            set
            {
                _ref_sohonnhan_vo = value;
            }
        }

        public IEnumerable<SOHONNHAN> REF_SOHONNHAN_CHONG
        {
            get
            {
                if (RefreshType == InfoTech.Core.Data.RefreshType.Allway || (RefreshType == InfoTech.Core.Data.RefreshType.OnlyonNull && _ref_sohonnhan_chong == null))
                    InfoTech.Core.Data.Receiver.TypeObject<SOHONNHAN>.Select(this, "REF_SOHONNHAN_CHONG", new[] { new Vector<string, string>("MAGIAODAN", "MAGIAODAN_CHONG") }, InfoTech.Core.Data.RelationType.OnetoMany);
                return _ref_sohonnhan_chong;
            }
            set
            {
                _ref_sohonnhan_chong = value;
            }
        }

    }
}
